<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
	MYDCONN(); 
	$Amount = '0,00';
	$UserFilter = '';

	if($_SESSION[$SESSOF]==52){$UserFilter = ' AND a.User = '.$_SESSION[$SESSID];}
	if(!isset($_POST['RefInvoice'])) {$_POST['RefInvoice'] = $GET[1]['Ref'];}?>
	<table width="98%"  border="0" cellpadding="2" cellspacing="1" bgcolor="#EAEAEA">
        <tr bgcolor="#F8F8F8">
          <td colspan="4">Descrição</td>
          <td>Natureza</td>
          <td>Fornecedor</td>
          <td>Funcionário</td>
          <td>Data</td>
          <td>Quant.</td>
          <td>PreÇo</td>
          <td>Prom.</td>
          <td>IVA</td>
          <td>Total</td>
          <td rowspan="2" align="center">
		  <?php mn_field('button','ED','addArticle','','','','','insert" onclick="
			document.edtCdcInvoice.action=\'_response/rsproxy.php?pr=cdc_article\';
			subform(\'edtCdcInvoice\',\'invItems\');'); ?></td>
        </tr>
        <tr bgcolor="#F8F8F8">
          <td colspan="4"><?php mn_field('text','ED','ArtDescription','','255','30','',''); ?></td>
          <td>-</td>
          <td>-</td>
          <td><?php 
		mn_field('select','ED','User','',"SELECT main_users.ref AS ID, NAME FROM main_users
		LEFT JOIN hrs_users ON User = main_users.ref
		 WHERE (main_users.ref_office = {$_SESSION[$SESSOF]} OR hrs_users.ref_office = {$_SESSION[$SESSOF]}) AND Type = 2 GROUP BY main_users.ref ORDER BY name",'','','');?></td>
          <td><?php mn_field('date','ED','DateTime','','edtCdcInvoice','8','',''); ?></td>
        <td><?php mn_field('text','ED','ArtQuantity','1','10','2','','" onKeyUp="ArticleAmount(this.form);'); ?></td>
          <td><?php mn_field('text','ED','ArtUAmount','0.00','14','4','','" onKeyUp="ArticleAmount(this.form);'); ?></td>
          <td><?php mn_field('text','ED','ArtPromo','0.00','6','4','','" onKeyUp="ArticleAmount(this.form);'); ?></td>
          <td><?php mn_field('select','ED','ArtTaxPercent','',"SELECT PERCENT AS ID, PERCENT AS NAME FROM ccenter_gov_tax",'','','" onChange="ArticleAmount(this.form);');?></td>
          <td><?php mn_field('text','ED','ArtAmount','0.00','20','4','','" readonly="'); ?></td>
        </tr>
        <?php
	   $List = $GLOBALS['MYD']->db_array("SELECT 
	      			main_users.name AS User,
					main_offices.name AS Office,
	   				a.ArtReference,
	   				a.Ref,
	   				a.ArtReference,
					a.Description,
					a.Quantity,
					a.UAmount,
					a.IvaPercent,
					a.Promo,
					a.Amount,
					a.CODE,
					a.Provider,
					a.sysTime
	  			FROM ccenter_invarticles AS a
				LEFT OUTER JOIN main_users ON main_users.ref = a.User
				LEFT OUTER JOIN main_offices ON main_offices.ref = a.Office
				WHERE RefInvoice = {$_POST['RefInvoice']} 
				AND a.Office = {$_SESSION[$SESSOF]} {$UserFilter}
				AND a.Status != 5");
	for($r = 1; $r <= $List[0]; $r++) {
  echo '<tr bgcolor="#B0C0D0">
        <td colspan="4">'.$List[$r]['Description'].'</td>
        <td>'.$List[$r]['CODE'].'</td>
        <td>'.$List[$r]['Provider'].'</td>
        <td>'.$List[$r]['User'].'</td>
        <td align="right">'.$List[$r]['sysTime'].'</td>
        <td align="right">'.$List[$r]['Quantity'].'</td>
        <td align="right">'.$List[$r]['UAmount'].'</td>
        <td>'.$List[$r]['Promo'].'</td>
        <td>'.round($List[$r]['IvaPercent']).'%</td>
        <td align="right">'.$List[$r]['Amount'].'</td>
		<td>'; 
		mn_field('button','ED','delArticle','','','','','delete" onclick="
			document.edtCdcInvoice.action=\'_response/rsproxy.php?pr=cdc_article&ACT=RT&RCINV='.$List[$r]['Ref'].'\';
			subform(\'edtCdcInvoice\',\'invItems\');'); echo '</td>
		</tr>';
	  $Amount += $List[$r]['Amount'];
	  } ?>
    </table>